package dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import model.Board;


//BoFrontController
public class BoardDAO {

	
	public List selectAllByTable(String table){
		try {		
			List list=BoardSqlMap.selectAllByTable(table);
			System.out.println("lise size="+list.size());
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
		}return null;
	}
	
	public void updateReadCount(int num) {
		/*try {
			BoardSqlMap.updateReadCount(num);
		} catch (SQLException e) {
			e.printStackTrace();
		}*/
	}
	
	
	public Board selectBoardByNum(HashMap map) {
		try {
			BoardSqlMap.updateReadCount(map);
			Board theBoard=BoardSqlMap.selectBoardByNum(map);
			return theBoard;
		} catch (SQLException e) {
			
		} 
		return null;
	}

	public int updateBoard(HttpServletRequest req) {
		String num = req.getParameter("num");
		int n = Integer.parseInt(num);
		String table = req.getParameter("table");
		if (table == null)	table = "board";
		String content=req.getParameter("content");
		String subject=req.getParameter("subject");
		String pass=req.getParameter("pass");
		String file=req.getParameter("file");
		Board board=new Board(table, n, "", "", subject, content, file, 0, 0, 0, 0, null);
		try {
			return BoardSqlMap.updateBoard(board);
		} catch (SQLException e) {		
			e.printStackTrace();
		}
		return -1;
	}

}
